package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.NetworkPrePayDealTab;
import com.ruoyi.logistic.domain.NetworkPrePayRechargeDeductionAudit;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkPrePayDealTabVo;
import com.ruoyi.logistic.domain.vo.NetworkPrePayRechargeDeductionAuditVo;
import com.ruoyi.logistic.service.NetworkPrePayDealTabService;
import com.ruoyi.logistic.service.NetworkPrePayRechargeDeductionAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/payRechargeDeductionAudit")
@RestController
@Api(tags = "网点财务_站点预付款_充值扣款审核")
public class NetworkPrePayRechargeDeductionAuditController {
    @Autowired
    private NetworkPrePayRechargeDeductionAuditService networkPrePayRechargeDeductionAuditService;
    @Autowired
    private TableService tableService;
    @ApiOperation("显示全部")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkPrePayRechargeDeductionAudit> sheets = networkPrePayRechargeDeductionAuditService.selectAll(pageDate);
        if (sheets == null || sheets.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(sheets));
        }
    }
    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkPrePayRechargeDeductionAudit sheet){
        Boolean isAdd = networkPrePayRechargeDeductionAuditService.insert(sheet);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody NetworkPrePayRechargeDeductionAudit sheet){
        Boolean isUpdate = networkPrePayRechargeDeductionAuditService.update(sheet);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkPrePayRechargeDeductionAuditService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody NetworkPrePayRechargeDeductionAuditVo vo){
        if (vo.getNetworkNameId() == null || vo.getStartTime() == null || vo.getEndTime() == null){
            return R.fail("时间信息和网点信息为必传字段！");
        }
        List<NetworkPrePayRechargeDeductionAudit> sheets = networkPrePayRechargeDeductionAuditService.search(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkPrePayRechargeDeductionAudit());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(sheets));
        jsonObject.put("fields", fieldList);
        if (sheets == null || sheets.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
